package com.ssy.lingxi.member.merchant.entity;

import com.fasterxml.jackson.annotation.JsonBackReference;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Objects;

/**
 * 会员自定义的组织机构
 * @author 万宁
 * @version 2.0.0
 * @date 2020-06-28
 */
@Entity
@Table(schema = "public", name = "ms_mc_member_organization", indexes = {@Index(name = "ms_mc_member_organization_key_idx", columnList = "key"), @Index(name = "ms_mc_member_organization_member_id_idx", columnList = "member_id")})
public class MemberOrganizationDO implements Serializable {
    private static final long serialVersionUID = 7326342631768769822L;

    @Id
    @GeneratedValue(strategy= GenerationType.SEQUENCE,generator="member_organization_seq")
    @SequenceGenerator(sequenceName="ms_mc_member_organization_seq", name="member_organization_seq",allocationSize = 1)
    private Long id;

    /**
     * 父节点Id
     */
    @Column
    private Long parentId;

    /**
     * 机构标识（用于树形菜单)
     */
    @Column(columnDefinition = "varchar(200)")
    private String key;

    /**
     * 机构代码
     */
    @Column(columnDefinition = "varchar(20)")
    private String code;

    /**
     * 机构名称
     */
    @Column(columnDefinition = "varchar(40)")
    private String title;

    /**
     * 同级内排序
     */
    @Column(name="org_order", columnDefinition = "int4", nullable = false)
    private Integer order;

    /**
     * 菜单层级，从1开始
     */
    @Column(columnDefinition = "int4", nullable = false)
    private Integer level;

    /**
     * 机构描述
     */
    @Column(columnDefinition = "varchar(64)")
    private String remark;

    /**
     * 多对一双向关联会员
     */
    @JsonBackReference
    @ManyToOne(cascade = CascadeType.DETACH, fetch = FetchType.LAZY)
    @JoinColumn(name = "member_id", referencedColumnName = "id")
    private MemberDO member;

    /**
     * 一对一双向关联门店
     */
    @OneToOne(cascade = CascadeType.DETACH, fetch = FetchType.LAZY)
    @JoinColumn(name = "store_id", referencedColumnName = "id")
    private MemberStoreDO store;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Long getParentId() {
        return parentId;
    }

    public void setParentId(Long parentId) {
        this.parentId = parentId;
    }

    public String getKey() {
        return key;
    }

    public void setKey(String key) {
        this.key = key;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public Integer getOrder() {
        return order;
    }

    public void setOrder(Integer order) {
        this.order = order;
    }

    public Integer getLevel() {
        return level;
    }

    public void setLevel(Integer level) {
        this.level = level;
    }

    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }

    public MemberDO getMember() {
        return member;
    }

    public void setMember(MemberDO member) {
        this.member = member;
    }

    public MemberStoreDO getStore() {
        return store;
    }

    public void setStore(MemberStoreDO store) {
        this.store = store;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        MemberOrganizationDO that = (MemberOrganizationDO) o;
        return Objects.equals(id, that.id);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id);
    }
}
